#include "NmiHelper.h"

//struct rt_semaphore nmi_sem;

/**
 * @brief  NMI (port falling) initialize.
 * @param  None
 * @retval None
 */
void NMI_FALLING_Init(void){
	stc_nmi_init_t stcNmiInit;
	/* NMI interrupt configure */
    (void)NMI_StructInit(&stcNmiInit);
    stcNmiInit.u32Src = NMI_SRC_PIN;
	stcNmiInit.u32Edge = NMI_TRIG_FALLING;
	stcNmiInit.u32Filter = NMI_FILTER_ON;
	stcNmiInit.u32FilterClock = NMI_FCLK_DIV8;
    (void)NMI_Init(&stcNmiInit);
}

/**
 * @brief  NMI IRQ Handler.
 * @param  None
 * @retval None
 */
uint32_t nmi_tick = 0;
__attribute__((at(0x200F0FFC))) uint8_t set_reset;
void NMI_Handler(void)
{
//	if ( rt_sem_release(&nmi_sem) != RT_EOK ) {
//		__NVIC_SystemReset();
//	}
	//rt_sem_release(&nmi_sem);
	nmi_tick = rt_tick_get();
	DDL_DelayMS(1000);
	if (GPIO_ReadInputPins(RESET_PORT, RESET_PIN) == PIN_SET) {
		set_reset = 0xEF;
	}
	__NVIC_SystemReset();
}

//void Nmi_Task_Run(void *parmameter) {
//	for (;;){
//		rt_sem_take(&nmi_sem, RT_WAITING_FOREVER);
//		rt_kprintf("get a nmi\n");
//	}
//}
